<!-- 支付1元即送2000元股票策略 -->
<template>
    <div class="warp">
        <div class="bg">
            <div class="content">
                <div class="kuang">
                    <div class="inputBox">
                        <div class="row" style="margin-top: 0.59rem;">
                            <input type="text" placeholder="请输入手机号" class="input_phone" v-model="phone" maxlength="11"/>
                        </div>
                        <div class="row">
                            <input type="password" placeholder="密码（6-18位的字母或数字）" class="input_paw" v-model="pawd" maxlength="18"/>
                        </div>
                        <div class="row dis">
                            <input type="text" placeholder="请输入验证码" class="input_code" v-model="codeM" maxlength="4"/>
                            <div class="send_btn1" v-show="show" @click="getCode"></div>
                            <div class="send_btn2" v-show="!show">{{count}}s后重试</div>
                        </div>
                        <div class="row flex">
                            <img src="../../assets/img/zhuce/no_checked.png" alt="" v-show="!checked" class="checked" @click="handChecked">
                            <img src="../../assets/img/zhuce/checked.png" alt="" v-show="checked" class="checked" @click="handChecked">
                            <span style="margin-left: 0.2rem;">我已阅读并同意</span>
                            <span class="xy" @click="dialogTableVisible = true">《平台注册协议》</span>及
                            <span class="rule">活动细则</span>
                        </div>
                        <div class="zhuce">
                            <div class="btn1" @click="zhuce"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- 协议书 -->
        <el-dialog :visible.sync="dialogTableVisible" width="86%" top="5vh">
            <img src="../../assets/img/zhuce/xieyi.png" alt="" width="100%"/>
        </el-dialog>
    </div>
</template>

<script>
    import MobileDetect from 'mobile-detect'
    import { error,success,isMobile,isPawd } from '../../common/js/uilt'
    export default {
        data() {
            return {
                phone: '',
                pawd: '',
                codeM: '',
                checked: true,
                show: true,
                count: '',
                timer: null,
                dialogTableVisible: false,
                isAndroid: false,
                isiOS: false,
                codeDate: '',
                agent: '', //渠道号
                brand_model: '',//手机型号
                phone_model: '' //手机系统
            }
        },
        mounted () {
            if(!this.$route.query.agent) {
                this.agent = '999';
            } else {
                this.agent = this.$route.query.agent;
            }
            // 百度流量统计代码
            const script = document.createElement('script');
            script.src = 'https://s13.cnzz.com/z_stat.php?id=1274594944&web_id=1274594944';
            script.language = 'JavaScript';
            document.body.appendChild(script);
            // 百度流量统计代码
            if (window._czc) {
                let location = window.location;
                let contentUrl = location.pathname + location.hash;
                let refererUrl = '/';
                window._czc.push(['_trackPageview', contentUrl, refererUrl]);
                window._czc.push(["_setCustomVar","访客渠道",this.agent,2]);
            }

            Array.prototype.contains = function(needle) { 
                for (i in this) { 
                    if (this[i].indexOf(needle) > 0) 
                    return i; 
                } 
                return -1; 
            } 
            var device_type = navigator.userAgent;//获取userAgent信息 
            var md = new MobileDetect(device_type);//初始化mobile-detect 
            var os = md.os();//获取系统 
            var model = ""; 
            if (os == "iOS") {//ios系统的处理 
                os = md.version("iPhone"); 
                // os = md.os() + md.version("iPhone"); 
                model = md.mobile(); 
            } else if (os == "AndroidOS") {//Android系统的处理 
                os = md.version("Android"); 
                // os = md.os() + md.version("Android"); 
                var sss = device_type.split(";"); 
                var i = sss.contains("Build/"); 
                if (i > -1) { 
                    model = sss[i].substring(0, sss[i].indexOf("Build/")); 
                } 
            }
            this.brand_model = model; //型号
            this.phone_model = os; //系统
        },
        methods: {
            handChecked() { //同意协议
                this.checked = !this.checked;
            },
            getCode(){ //验证码
                this.$api.code({ phone_no: this.phone }).then(res => {
                    this.codeDate = res.code;
                    if(res.mark == 0) {
                        success(res.tip);
                        var TIME_COUNT = 60;
                        if (!this.timer) {
                            this.count = TIME_COUNT;
                            this.show = false;
                            this.timer = setInterval(() => {
                                if (this.count > 0 && this.count <= TIME_COUNT) {
                                    this.count--;
                                } else {
                                    this.show = true;
                                    clearInterval(this.timer);
                                    this.timer = null;
                                }
                            }, 1000)
                        }
                    } else {
                        error(res.tip);
                    }
                });
            },
            zhuce() { //注册
                if(this.phone == '') {
                    error('请输入手机号码');
                    return;
                }
                if(!(isMobile(this.phone))) {
                    error('请输入正确的手机号码');
                    return;
                }

                if(this.pawd == ''){
                    error('请输入6-18位的字母或数字组合密码');
                    return;
                }
                if(!(isPawd(this.pawd))) {
                    error('密码必须是6-18位的字母或数字组合');
                    return;
                }

                if(this.codeM == ''){
                    error('请输入验证码');
                    return;
                }
                if(this.codeM != this.codeDate){
                    error('验证码错误');
                    return;
                }

                if(this.checked == false){
                    error('请同意我们的协议书');
                    return;
                }
                this.$api.register({ agent: this.agent,brand_model: this.brand_model,phone_model:this.phone_model,app_edition: 'H5',invite_pepo: '',member_name: this.phone,phone_no: this.phone, member_psw: this.pawd, autoCode: this.codeM,push_code: '',register_ip: '' }).then(res => {
                    if(res.mark==0){
                        success(res.tip);
                        var u = navigator.userAgent;
                        this.isAndroid = u.indexOf("Android") > -1 || u.indexOf("Adr") > -1; //android终端
                        this.isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
                        if(this.isAndroid) {
                            window.location.href = 'http://a.app.qq.com/o/simple.jsp?pkgname=com.stock.hotstocksbus';
                        } else {
                            window.location.href = 'https://www.pgyer.com/sZp2';
                        }
                    } else {
                        error(res.tip);
                    }
                });
            }
        }
    };
</script>
<style lang='less' scoped>
    .bg{
        overflow: hidden;
        width: 100%;
        height: 24rem;
        background: url(../../assets/img/zhuce/payoneMoney_bg.png) center no-repeat;
        background-size: 100%;
        .content{
            overflow: hidden;
            width: 100%;
            height: 24rem;
            .kuang{
                width: 7.11rem;
                height: 6.58rem;
                background: url(../../assets/img/zhuce/kuang.png) center no-repeat;
                background-size: 100%;
                margin: 9.31rem auto 0;
            }
            .inputBox{
                text-align: center;
                width: 6.04rem;
                margin: 6.16rem auto 0;
                overflow: hidden;
                .row {
                    margin-bottom: 0.29rem;
                }
                .input_phone,.input_paw,.input_code{
                    height: 0.92rem;
                    font-size: 0.36rem;
                    color: #666;
                    padding: 0.28rem 15px 0.28rem 0.86rem;
                    border: none;
                    -webkit-appearance: none;
                    outline: 0;
                    box-sizing: border-box;
                    line-height: 0.52rem; /* for non-ie */  
                    &::-webkit-input-placeholder {
                        /* placeholder颜色  */
                        color: #BEBEBE;
                    }
                }
                .input_phone{
                    width: 100%;
                    background: url(../../assets/img/zhuce/input_phone.png) center no-repeat;
                    background-size: 100% 100%;
                }
                .input_paw{
                    width: 100%;
                    background: url(../../assets/img/zhuce/input_paw.png) center no-repeat;
                    background-size: 100% 100%;
                }
                .input_code{
                    flex: 1;
                    width: 2.32rem;
                    background: url(../../assets/img/zhuce/input_code.png) center no-repeat;
                    background-size: 100% 100%;
                }
                .send_btn1,.send_btn2{
                    width: 2.34rem;
                    height: 1rem;
                    line-height: 0.9rem;
                    margin-left: 0.2rem;
                }
                .send_btn1{
                    flex: 1;
                    background: url(../../assets/img/zhuce/code.png) 0.05rem center no-repeat;
                    background-size: 100% 100%;
                }
                .send_btn2{
                    flex: 1;
                    line-height: 0.9rem;
                    background: url(../../assets/img/zhuce/no_code.png) 0.05rem center no-repeat;
                    background-size: 100% 100%;
                    color: #a24030  ;
                    font-size: 0.38rem;
                }
                .dis{
                    display: flex;
                    flex-direction: row;
                    justify-content: space-between;
                }
                .flex{
                    display: flex;
                    flex-direction: row;
                    color: #C2C2C2;;
                    font-size: 0.26rem;
                }
                .checked{
                    width: 0.38rem;
                    height: 0.38rem;
                }
                .xy{
                    display: inline-block;
                    height: 0.38rem;
                    color: #ED654E;
                }
                .zhuce{
                    display: flex;
                    justify-content: center;
                    margin-top: 0.34rem;
                    .btn1{
                        width: 6.14rem;
                        height: 1.04rem;
                        line-height: 0.9rem;
                        background: url(../../assets/img/zhuce/registerBtn.png) center no-repeat;
                        background-size: 100% 100%;
                    }
                }
            }
        }
    }
</style>